<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

    <title>用户</title>

    <link rel="shortcut icon" href="assets/img/logo2x.png"/>
    <!-- Bootstrap core CSS -->
    <link href="assets/css/bootstrap.css" rel="stylesheet"/>
    <!--external css-->
    <link rel="stylesheet" type="text/css" href="assets/font-awesome/css/font-awesome.css"/>
    <link rel="stylesheet" type="text/css" href="assets/css/zabuto_calendar.css">
    <link rel="stylesheet" type="text/css" href="assets/js/gritter/css/jquery.gritter.css"/>
    <link rel="stylesheet" type="text/css" href="assets/lineicons/style.css">

    <!-- Custom styles for this template -->
    <link href="assets/css/style.css" rel="stylesheet">
    <link href="assets/css/style-responsive.css" rel="stylesheet">

    <script src="assets/js/chart-master/Chart.js"></script>

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

<section id="container">

    <div th:replace="tools :: header"></div>

    <div th:replace="tools :: sidebar "></div>

    <!-- **********************************************************************************************************************************************************
    MAIN CONTENT
    *********************************************************************************************************************************************************** -->
    <!--main content start-->
    <section id="main-content">
        <section class="wrapper site-min-height">
            <div class="form-panel">
                <div class="btn-group">
                    <button class="btn " onclick="window.history.back()"><i class="fa fa-angle-left"></i> 返回</button>
                    <button class="btn " onclick="javascript:location.reload();"><i class="fa fa-refresh"></i> 刷新</button>
                </div>
            </div>

            <div class="row">
                <div class="col-md-12">
                    <div class="form-panel">
                        <div class="col-md-12 centered">
                            <h3><i class="fa fa-angle-right"></i> 用户管理 <i class="fa fa-angle-left"></i></h3>
                        </div>
                        <table class="table table-striped table-advance table-hover">

                            <thead class="table-bordered">
                            <tr class="bg-success">
                                <th><i class="fa fa-user"></i> 用户名</th>
                                <th><i class="fa fa-user-md"></i> 真实姓名</th>
                                <th><i class="fa fa-envelope"></i> 邮箱</th>
                                <th><i class="fa fa-venus-mars"></i> 性别</th>
                                <th><i class=" fa fa-birthday-cake"></i> 生日</th>
                                <th><i class=" fa fa-phone"></i> 手机号</th>
                                <th><i class=" fa fa-calendar"></i> 注册日期</th>
                                <th><i class=" fa fa-cog"></i> 操作</th>
                                <th></th>
                            </tr>
                            </thead>

                            <tbody>
                            <tr th:each="users : ${page.data}" id="userdata">
                                <td th:text="${users.username}"></td>
                                <td>
                                    <a th:href="'/viewuser?userid='+${users.infoid}" th:text="${users.realname}"></a>
                                </td>
                                <td th:text="${users.email}"></td>
                                <td th:text="${users.gender}"></td>
                                <td th:text="${users.birthday}"></td>
                                <td th:text="${users.phone}"></td>
                                <td th:text="${users.regtime}"></td>
                                <td>
                                    <button class="btn btn-sm btn-danger"
                                            th:onclick="'delUser(\''+${users.infoid}+'\')'">删除
                                    </button>
                                </td>
                            </tr>

                            </tbody>
                            <tfoot>

                            </tfoot>

                        </table>
                        <div class="inline-block form-inline">
                            <button class="btn" onclick="switchPage('pre')"> 上一页</button>
                            <button class="btn" onclick="switchPage('nxt')"> 下一页</button>
                            <button class="btn" onclick="switchPage('topg')">前往</button>
                            <input id="topage" type="number" class="form-control" placeholder="请输入页码">
                            第 <span class="cpspan" th:text="${page.c}"></span> 页
                            共 <span th:text="${totalpg}"></span>页
                            <input id="cpage" hidden th:value="${page.c}">
                            <input id="totalpg" hidden th:value="${totalpg}">
                        </div>

                    </div>
                </div>
            </div>
        </section>
        <! --/wrapper -->

    </section>

    <!--main content end-->

    <!--**********************************************************************************************
    Footer
    **********************************************************************************************-->

    <!--footer start-->
    <footer class="site-footer">
        <div class="text-center">
            Copyright © 2018 David Bai
            <a href="#main-content" class="go-top">
                <i class="fa fa-angle-up"></i>
            </a>
        </div>
    </footer>
    <!--footer end-->
</section>


<!-- js placed at the end of the document so the pages load faster -->
<script src="assets/js/jquery.js"></script>
<script src="assets/js/jquery-1.8.3.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script class="include" type="text/javascript" src="assets/js/jquery.dcjqaccordion.2.7.js"></script>
<script src="assets/js/jquery.scrollTo.min.js"></script>
<script src="assets/js/jquery.nicescroll.js" type="text/javascript"></script>
<script src="assets/js/jquery.sparkline.js"></script>

<!--common script for all pages-->
<script src="assets/js/common-scripts.js"></script>
<script>
    function switchPage(opt) {
        switch (opt) {

            case "pre":
                if ($("#cpage").val() == 1) {
                    alert("已经是首页了");
                } else {
                    location.href = "/users?c=" + $(".cpspan").text() + "&o=" + opt;
                }
                break;
            case "nxt":
                if ($("#cpage").val() == $("#totalpg").val()) {
                    alert("没有下一页了");
                } else {
                    location.href = "/users?c=" + $(".cpspan").text() + "&o=" + opt;
                }
                break;
            case "topg":
                if ($("#topage").val() <= $("#totalpg").val() && $("#topage").val() > 0) {
                    location.href = "/users?c=" + $("#topage").val() + "&o=" + opt;
                } else {
                    alert("页码有误");
                }
                break;
        }
        // location.href="/users?c="+$(".cpspan").text()+"&o="+opt,this;
    }

    function delUser(userid) {
        if (confirm("确然要删除？")) {
            $.post("/deluser", {userid: userid}, function () {
                alert("删除成功");
                location.reload();
            })
        }
    }
</script>

</body>
</html>
